package com.e3.core.base;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;

public final class DAOHelper {
	
	private static SessionFactory sessionFactory;
	
	protected static void setSessionFactory(SessionFactory sf){
		sessionFactory = sf;
	}
	
	public static <T extends SuperDAO> T createDAOInstance(Class<T> clazz){
		T dao = null;
		try {
			dao = (T)clazz.newInstance();
			dao.setSessionFactory(sessionFactory);
			HibernateTemplate hibTemplate = new HibernateTemplate(sessionFactory);
			dao.setHibTemplate(hibTemplate);
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		
		return dao;
	}
}
